package soundChaser;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import javazoom.jl.decoder.JavaLayerException;
import javazoom.jl.player.Player;

public class AudioPlayer extends Thread{

	private String mp3src;
	private Player player = null;

	/**
	 * Konstruktor
	 * 
	 * @param mp3Source
	 */
	public AudioPlayer(String mp3Source) {
		this.mp3src = mp3Source;

		InputStream mp3stream = null;

		File mp3file = new File(mp3src);

		try {
			mp3stream = new FileInputStream(mp3file);
		} catch (FileNotFoundException e) {

			e.printStackTrace();
		}

		try {
			player = new Player(mp3stream);

		} catch (JavaLayerException e) {
			e.printStackTrace();
		}
	}

	/**
	 * PLAY-Methode
	 */
	private void play() {
		try {
			player.play();
		} catch (JavaLayerException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public boolean getIsComplete() {
		return player.isComplete();
	}

	/**
	 * Gets the exact Position in MilliSeconds
	 * @return
	 */
	public int getPosition() {
		return player.getPosition();
	}

	public void closePlayer() {
		player.close();
	}

	public void run(){
		this.play();
	}
	
}
